using System;
using System.Collections.Generic;
using System.Linq;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.Dialog;

namespace Socialite
{
	[MonoTouch.Foundation.Register("SearchScreen")]
	public partial class SearchScreen : DialogViewController
	{
		UIBarButtonItem	_searchButton;
		SearchCriteria _searchCriteria;

		public SearchScreen () : base (UITableViewStyle.Grouped, null)
		{
			_searchCriteria = new SearchCriteria ();
			var bctx = new BindingContext (null, _searchCriteria, "Search Filter");
			Root = bctx.Root;
			Root.Add(new Section(){new PriceRangeSelectorElement(_searchCriteria)});

			//Control the space between sections...
			this.TableView.SectionFooterHeight = 2;
			this.TableView.SectionHeaderHeight = 2;
		}
		
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			NavigationItem.BackBarButtonItem = new UIBarButtonItem("Back", UIBarButtonItemStyle.Plain, null);

			if (_searchButton == null)
				_searchButton = new UIBarButtonItem (
					"Go",
					UIBarButtonItemStyle.Done,
					(sender, args) => {NavigationController.PushViewController(new SearchResultsScreen(_searchCriteria), true);});
			
			NavigationItem.SetRightBarButtonItem (_searchButton, true);
		} 
	}
}
